package me.a_littlesquid.whitelist.events;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.Plugin;

import java.util.List;

import static org.bukkit.event.player.PlayerLoginEvent.Result.KICK_OTHER;

public class playerjoin implements Listener {
    @EventHandler
    public void onPlayerjoin(PlayerLoginEvent e){
        Boolean result=false;
        Player p=e.getPlayer();
        String pn=p.getDisplayName();
        Plugin config=me.a_littlesquid.whitelist.Whitelist.getProvidingPlugin(me.a_littlesquid.whitelist.Whitelist.class);
        List<String> playerlist=config.getConfig().getStringList("playerlist");
        for(String playername:playerlist){
            if(pn.equalsIgnoreCase(playername)){
                e.allow();
                result=true;
            }
        }
        if(result.equals(false)){
            e.disallow(KICK_OTHER,"很抱歉，你并不在白名单中");
        }
    }
}
